package com.clip.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.clip.dao.NoticeItemDAO;
import com.clip.entity.NoticeItem;
import com.clip.entity.User;

@Service
@Transactional
public class NoticeItemService {
	@Autowired
	private NoticeItemDAO noticeItemDAO;

	public void createObject(User user, int invitefriendnotice,String desc) {
		if(!findNotice(invitefriendnotice,user)){
			NoticeItem item=new NoticeItem();
			item.setItemid(invitefriendnotice);
			item.setUid(user.getId());
			item.setItemdesc(desc);
			this.noticeItemDAO.save(item);
		}
	}

	public boolean findNotice(int invitefriendnotice, User user) {
		String query="from NoticeItem ni where ni.uid="+user.getId()+" and ni.itemid="+invitefriendnotice;
		List list=noticeItemDAO.findByQuery(query);
		if(list==null||list.size()==0){
			return false;
		}else
			return true;
	}

}
